<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>AdminLTE | 仪表盘</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- bootstrap 3.0.2 -->
    <link href="/style/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- font Awesome -->
    <link href="/style/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <!-- Ionicons -->
    <link href="/style/css/ionicons.min.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="/style/css/AdminLTE.css" rel="stylesheet" type="text/css" />
    <!-- Morris charts -->
    <link href="/style/css/morris/morris.css" rel="stylesheet" type="text/css" />
    <link href="/style/css/morris/morris.css" rel="stylesheet" type="text/css" />


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
</head>

<body class="skin-blue">
    <!-- header logo: style can be found in header.less -->
    <header class="header">
        <a href="index.html" class="logo">
            <!-- Add the class icon to your logo image or logo icon to add the margining -->
            富乐电商
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-right">
                <ul class="nav navbar-nav">
                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <i class="glyphicon glyphicon-user"></i>
                            <span><?php echo cookie('nicename');?> <i class="caret"></i></span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- User image -->
                            <li class="user-header bg-light-blue">
                                <img src="/style/img/avatar3.png" class="img-circle" alt="User Image" />
                                <p>
                                    <?php echo cookie('nicename');?> - <?php echo cookie('identity');?>
                                    <small>注册日期：<?php echo (date("Y-m-d",$_COOKIE['created_at'])); ?></small>
                                </p>
                            </li>
                            <!-- Menu Footer-->
                            <li class="user-footer">
                                <div class="pull-left">
                                    <a href="<?php echo U('Home/User/index');?>" class="btn btn-default btn-flat">个人资料</a>
                                </div>
                                <div class="pull-right">
                                    <a href="<?php echo U('Home/Login/logout');?>" class="btn btn-default btn-flat">注销登录</a>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
    <div class="wrapper row-offcanvas row-offcanvas-left">
        <!-- Left side column. contains the logo and sidebar -->
        <aside class="left-side sidebar-offcanvas">
            <!-- sidebar: style can be found in sidebar.less -->
            <section class="sidebar">
                <!-- Sidebar user panel -->
                <div class="user-panel">
                    <div class="pull-left image">
                        <img src="/style/img/avatar3.png" class="img-circle" alt="User Image" />
                    </div>
                    <div class="pull-left info">
                        <p>你好, <?php echo cookie('nicename');?></p>
                        <small>运营经理</small>
                        <a href="#"><i class="fa fa-circle text-success"></i> 在线</a>
                    </div>
                </div>
                <!-- sidebar menu: : style can be found in sidebar.less -->
                <ul class="sidebar-menu">
                    <li>
                        <a href="<?php echo U('Home/Index/index');?>">
                            <i class="fa fa-dashboard"></i> 
                            <span>后台首页</span>
                        </a>
                    </li>
                    <li class="treeview active">
                        <a href="#">
                            <i class="fa fa-bar-chart-o"></i>
                            <span>刷单计划</span>
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="<?php echo U('Home/Shuadan/index');?>"><i class="fa fa-angle-double-right"></i> 本周期计划</a>
                            </li>
                            <?php if(($_SESSION['is_admin']) != "0"): ?><li><a href="<?php echo U('Home/Shuadan/add');?>"><i class="fa fa-angle-double-right"></i> 添加计划</a>
                            </li><?php endif; ?>
                            <li><a href="<?php echo U('Home/Shuadan/history');?>"><i class="fa fa-angle-double-right"></i> 历史计划</a>
                            </li>
                        </ul>
                    </li>
                    <?php if(($_SESSION['is_admin']) != "0"): ?><li class="treeview">
                        <a href="#">
                            <i class="fa fa-bar-chart-o"></i>
                            <span>用户管理</span>
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="<?php echo U('Home/User/lists');?>"><i class="fa fa-angle-double-right"></i> 所有用户</a>
                            </li>
                            <li><a href="<?php echo U('Home/User/add');?>"><i class="fa fa-angle-double-right"></i>添加用户</a>
                            </li>
                            <li><a href="<?php echo U('Home/User/index');?>"><i class="fa fa-angle-double-right"></i> 个人资料</a>
                            </li>
                        </ul>
                    </li>
                    <?php else: ?>
                    <li>
                        <a href="<?php echo U('Home/User/index');?>">
                            <i class="fa fa-envelope"></i> 
                            <span>个人资料</span>
                        </a>
                    </li><?php endif; ?>
                </ul>
            </section>
            <!-- /.sidebar -->
        </aside>

        <!-- Right side column. Contains the navbar and content of the page -->
        <aside class="right-side">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    后台首页
                    <small>控制面板</small>
                </h1>
            </section>

            <!-- Main content -->
            <section class="content">
                <div class="row">
                    <div class="col-md-12">
                        <!-- AREA CHART -->
                        <div class="box box-primary">
                            <div class="box-header">
                                <h3 class="box-title">刷单计划</h3>
                                <?php if($plane['lock']==0): ?><div id="plane_tools_btns" class="box-tools pull-right">
                                        <div class="btn-group">
                                            <a id="reload_plane_btn" href="#" class="btn btn-default" data-toggle="tooltip" title="" data-original-title="重新计算"><i class="fa fa-fw fa-refresh"></i></a>
                                            <a id="lock_plane_btn" href="#" class="btn btn-primary" data-toggle="tooltip" title="" data-original-title="锁定计划"><i class="fa fa-fw fa-lock"></i></a>
                                        </div>
                                    </div><?php endif; ?>
                            </div>
                            <div class="box-body chart-responsive">
                                <h3>刷单情况</h3>
                                <div class="chart" id="shuadan-chart" style="height: 300px;"></div>
                                <h3>流量情况</h3>
                                <div class="chart" id="flow-chart" style="height: 300px;"></div>
                            </div>
                            <div class="box-footer">
                                <table class="table table-hover">
                                    <tbody>
                                        <thead>
                                            <th>日期</th>
                                            <th>计划刷单数</th>
                                            <th>实际刷单数</th>
                                            <th>刷单对比</th>
                                            <th>计划流量</th>
                                            <th>实际流量</th>
                                            <th>流量对比</th>
                                            <th>计划转化率</th>
                                            <th>实际转化率</th>
                                            <th>转化率对比</th>
                                            <th>备注</th>
                                            <th>操作</th>
                                        </thead>
                                        <?php if(is_array($dans)): foreach($dans as $key=>$dan): ?><tr>
                                                <td><?php echo (date("Y-m-d",$dan["date"])); ?></td>
                                                <td><?php echo ($dan["plane_num"]); ?></td>
                                                <td><?php echo ($dan["real_num"]); ?></td>
                                                <td>
                                                    <?php if(($dan['real_num']) == "0"): ?><small class="badge bg-yellow">未进行</small>
                                                    <?php else: ?>
                                                    <?php if(($dan['num_contrast']) >= "0"): ?><small class="badge bg-green">+<?php echo ($dan["num_contrast"]); ?></small>
                                                        <?php else: ?>
                                                        <small class="badge bg-red"><?php echo ($dan["num_contrast"]); ?></small><?php endif; endif; ?>
                                                </td>
                                                <td><?php echo ($dan["flow_num"]); ?></td>
                                                <td><?php echo ($dan["real_flow"]); ?></td>
                                                <td>
                                                    <?php if(($dan['real_flow']) == "0"): ?><small class="badge bg-yellow">未进行</small>
                                                    <?php else: ?>
                                                    <?php $dan['flow_contrast'] = $dan['real_flow'] - $dan['flow_num'] ?>
                                                    <?php if(($dan['flow_contrast']) >= "0"): ?><small class="badge bg-green">+<?php echo ($dan['real_flow'] - $dan['flow_num']); ?></small>
                                                        <?php else: ?>
                                                        <small class="badge bg-red"><?php echo ($dan['real_flow'] - $dan['flow_num']); ?></small><?php endif; endif; ?>
                                                </td>
                                                <td><?php echo ($dan['plane_conver']*100); ?>%</td>
                                                <td><?php echo ($dan['real_conver']*100); ?>%</td>
                                                <td>
                                                    <?php if(($dan['real_flow']) == "0"): ?><small class="badge bg-yellow">未进行</small>
                                                    <?php else: ?>
                                                    <?php if(($dan['conver_contrast']) >= "0"): ?><small class="badge bg-green">+<?php echo ($dan['conver_contrast']*100); ?>%</small>
                                                        <?php else: ?>
                                                        <small class="badge bg-red"><?php echo ($dan['conver_contrast']*100); ?>%</small><?php endif; endif; ?>
                                                </td>
                                                <td><?php echo ($dan["description"]); ?></td>
                                                <td><a href="<?php echo U('edit',array('id'=>$dan['id']));?>" class="btn btn-sm btn-primary" title="修改"><i class="fa fa-edit"></i></a></td>
                                            </tr><?php endforeach; endif; ?>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.box-body -->
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col (LEFT) -->
                </div>
                <!-- /.row -->
            </section>
            <!-- /.content -->
        </aside>
        <!-- /.right-side -->
    </div>
    <!-- ./wrapper -->


    <!-- jQuery 2.1.1 -->
    <script src="/style/js/jquery-2.1.1.min.js" type="text/javascript"></script>
    <!-- Bootstrap -->
    <script src="/style/js/bootstrap.min.js" type="text/javascript"></script>
    <!-- AdminLTE App -->
    <script src="/style/js/AdminLTE/app.js" type="text/javascript"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="/style/js/AdminLTE/demo.js" type="text/javascript"></script>
    <!-- Morris.js charts -->
    <script src="/style/js/plugins/morris/raphael-min.js"></script>
    <script src="/style/js/plugins/morris/morris.min.js" type="text/javascript"></script>

    <script>
    $(function() {
        // AREA CHART
        // 显示图表
       $.ajax({
              url: "<?php echo U('plane_data',array('id'=>$plane['id']));?>",
              success: function(data){
                var area = new Morris.Line({
                element: 'shuadan-chart',
                resize: true,
                data: data,
                xkey: 'date',
                ykeys: ['plane_num','real_num'],
                labels: ['计划刷单数','实际刷单数'],
                lineColors: ['#a0d0e0','#f56954'],
                hideHover: false,
                xLabels: 'day'
            });
              },
            });
       $.ajax({
              url: "<?php echo U('plane_data',array('id'=>$plane['id']));?>",
              success: function(data){
                var area = new Morris.Line({
                element: 'flow-chart',
                resize: true,
                data: data,
                xkey: 'date',
                ykeys: ['flow_num','real_flow'],
                labels: ['计划流量','实际流量'],
                lineColors: ['#a0d0e0','#f56954'],
                hideHover: false,
                xLabels: 'day'
            });
              },
            });
       // 重新计算计划
       $('#reload_plane_btn').click(function(){
            $.ajax({
                url:"<?php echo U('reload_plane',array('id'=>$plane['id']));?>",
                success: function(data){
                location.reload();
                },
            });
        });
       // 锁定计划
       $('#lock_plane_btn').click(function(){
        $.ajax({
            url:"<?php echo U('lock_plane',array('id'=>$plane['id']));?>",
            success:function(data){
                $('#plane_tools_btns').remove();
            },
        });
       });
    });
    </script>

</body>

</html>